from django.shortcuts import render
from django.http import HttpResponse
from .models import *
from django.views.decorators.cache import cache_page
from django.core.cache import cache
import time
from .task import *

# Create your views here.
def index(request):
    return render(request,'booktest/index.html')
def editorhandle(request):
     html = request.POST.get('content')
     # test1 = Test1.objects.get(pk=1)
     # test1.hcontent = html
     # test1.save()
     test1 = Test1()
     test1.hcontent = html
     test1.save()
     context = {'content':html}
     return render(request,'booktest/showedit.html',context)
def showdb(request):
    # test1 = Test1.objects.all()
    # cache.set('test1',test1,120)
    test1 = cache.get('test1')
    # cache.delete('test1')
    # cache.clear()
    context = {'test1':test1}
    return render(request,'booktest/showdb.html',context)

# @cache_page(60)
def cachetest(request):
    return HttpResponse('index2')

def cachetest2(request):
    return render(request,'booktest/cache.html')

def mysearch(request):
    return render(request,'booktest/mysearch.html')

def celery1(request):
    # print('hello ...')
    # time.sleep(5)
    # print('world ...')

    sayhello.delay()

    return HttpResponse("hello world")